package fr.enseirbmatmeca.apms.spring.service.impl;

import java.util.ArrayList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fr.enseirbmatmeca.apms.hibernate.dao.UserDAO;
import fr.enseirbmatmeca.apms.spring.model.User;
import fr.enseirbmatmeca.apms.spring.service.UserManager;

/**
 * Implements business features to handler users
 * @author bmeurant
 */
public class UserManagerImpl implements UserManager {

    private final Log logger = LogFactory.getLog(UserManagerImpl.class);
    
    private UserDAO userDAO = null;

    /**
     * setter to allows spring to inject userDAO implementation
     * @param userDAO : object (implementation of userDAO interface) to inject.
     */
    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }
    
    /**
     * {@inheritDoc}
     */
    public boolean checkLogin (String login, String password) {
        return userDAO.checkLogin(login, password);
    }

    /**
     * {@inheritDoc}
     */
    public User changePassword(String login, String password) {
        User user = userDAO.getUser(login);
        if (user != null) {
            user.setPassword(password);
        }
        return user;
    }
    
    /**
     * {@inheritDoc}
     */
    public User getUser(String login) {
        return userDAO.getUser(login);
    }

    public User getUserFromLogAndAuthToken(String userlogin,String authtoken) {
        return userDAO.getUserFromLogAndAuthToken(userlogin,authtoken);
    }
    
    /**
     * {@inheritDoc}
     */
	public User createUser(String login, String pushToken) {
		System.out.print("UserManagerImpl : createUser : "+login);
		User user = userDAO.createUser(login,pushToken);
		return user;
	}

}